package com.zusmart.core.bean.support;

import com.zusmart.core.bean.BeanDefinition;
import com.zusmart.core.bean.cause.BeanInstanceCreateException;
import com.zusmart.core.bean.cause.BeanInstanceDestoryException;
import com.zusmart.core.bean.cause.BeanInstanceInitialException;
import com.zusmart.core.bean.cause.BeanInstanceInjectException;
import com.zusmart.core.bean.cause.BeanInstanceReleaseException;

public class BeanInstanceHandlerForSingleton extends AbstractBeanInstanceHandler {

	private Object beanInstance;

	public BeanInstanceHandlerForSingleton(BeanDefinition beanDefinition) {
		super(beanDefinition);
	}

	@Override
	public void doCreate() throws BeanInstanceCreateException {
		this.beanInstance = this.getBeanDefinition().getBeanInstanceCreator().createBeanInstance();
	}

	@Override
	public void doInject() throws BeanInstanceInjectException {
		this.doInjectFields(this.beanInstance);
		this.doInjectMethods(this.beanInstance);
	}

	@Override
	public void doInitial() throws BeanInstanceInitialException {
		this.doInvokeInitialMethods(this.beanInstance);
	}

	@Override
	public void doRelease() throws BeanInstanceReleaseException {
		this.doInovkeDestoryMethods(this.beanInstance);
	}

	@Override
	public void doDestory() throws BeanInstanceDestoryException {
		this.beanInstance = null;
	}

	@Override
	public Object getBeanInstance() throws BeanInstanceCreateException {
		return this.beanInstance;
	}

}